var router = require('libs/router').router;
var pages = require('libs/pages');
var ItemMixin = require('mixins/item');
var libs = require('libs/libs');
var List = require('modules/list/load_list')(true, 'sendStatus');

var api = libs.api;

var bindEvent = function(){

    $('.hlist').find('li:first p.title').css({fontSize:'0.16rem',color:'#fa8733'})
}

var SendDetails = React.createClass({
    mixins: [ItemMixin],
    render: function(){
        if(this.props.data){
            var waterstatus_data = this.props.data;
            var waterstatus_dataHtml = [];
            waterstatus_data.map(function(item, i){
                 waterstatus_dataHtml.push(
                     <div className="box" key={'waterstatus'+i}>
                         <p className="title">{(function(){
                                 var _d = item.description,
                                     _c = item.createBy,
                                     _p = item.phone;
                                 if (_d.indexOf('领单')>-1){
                                     return _c+''+'('+_p+')'+_d;
                                 }
                                 else {
                                     return _d
                                 }
                             })() }</p>
                         <p className="time">{item.createTime}</p>
                     </div>
                 )
            })
        }
        return(
            <div className="send-status flex flex-v">
                <div className='flex-1 f-oTouch'>
                    <List data={waterstatus_dataHtml} listClass="send-status-list"/>
                </div>
            </div>
        )
    }
})

function start(name){
    return pages.new({
        boot:function(){},
        // goback: function(){
        //     var _pre = router.pre();
        //     if (_pre.hash!=='send/details'){
        //         router.cb = function(name){
        //             router('send/details');
        //         }
        //     }
        //     else {
        //         router.cb = function(name){
        //             router.goback()
        //         }
        //     }
        // },
        trigger: function(self,prevData){
            this.libs.changeTitle('日志跟踪');
            // var _orderId = JSON.parse(sessionStorage.getItem('sendOrderId'));
            var _orderId = prevData.orderid
            var _this = this;
            var login = SA.get('USER').login;
            var params = {
                method: 'get',
                login:login,
                orderId:_orderId
            };
            api.req('/orderLog',params,function(data){
                console.log(data);
                _this.main(_this,data);
            });

        },
        main: function(self,data){
            this.render(
                <SendDetails itemDefaultMethod={bindEvent} data={data} />,
                document.getElementById(name)
            )
        },
        end: function(){
            React.unmountComponentAtNode(document.getElementById(name))
        }
    })
}


module.exports = start;
